layui.use(['jquery','layer','form','table','laypage'], function() {
    var laypage = layui.laypage;
    var $ = layui.jquery;
    var form = layui.form;
    var table = layui.table;
    var layer = layui.layer; //独立版的layer无需执行这一句

    var id=$.cookie('adminId');//在myInfo.js的25行存入中存入的
    $(function () {
        //保存修改密码
        $("#submit").on('click', function(){
            var oldPwd=$("#oldPwd").val();
            var newPwd =$("#newPwd").val();
            var reNewPwd =$("#reNewPwd").val();
            if(""==oldPwd.trim()||null==oldPwd.trim()){
                layer.msg("请输入原密码！", {icon: 2,time:2000,shade:0.2});
                return false;
            }
            if(newPwd.trim()==""||newPwd.trim()==null){
                layer.msg("密码不能为空", {icon: 2,time:2000,shade:0.2});
                return false;
            }else if(newPwd.trim().length<6||newPwd.trim().length>20){
                layer.msg("密码长度在6-20位", {icon: 2,time:2000,shade:0.2});
                return false;
            }
            if(reNewPwd.trim()==""||reNewPwd.trim()==null){
                layer.msg("密码不能为空", {icon: 2,time:2000,shade:0.2});
                return false;
            }else if(reNewPwd!=newPwd){
                layer.msg("两次密码输入不一致", {icon: 2,time:2000,shade:0.2});
                return false;
            }
            $.ajax({
                url:"/login/updatePwd",
                type:"post",
                data:{"id":id,"oldPwd":oldPwd,"newPwd":newPwd},
                success:function (result) {
                    if(result.code==0){
                        layer.alert("修改成功，请重新登录！",function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                            window.parent.location.reload();
                            $.ajax({
                                url:"/login/loginOut",
                                type:"get",
                                success:function (result) {
                                    if(result.code==0){
                                        layer.msg("操作成功！");
                                        window.location.href="../../view/login.html";
                                    }else {
                                        layer.msg(result.message, {icon: 2,time:2000,shade:0.2});
                                    }
                                }
                            });

                        });

                    }else {
                        layer.msg(result.message, {icon: 2,time:2000,shade:0.2});
                    }

                }
            });
            return false;
        });

    })


})